'use strict';

if (process.env.NODE_ENV === undefined) {
  process.env.NODE_ENV = 'development';
}

const Koa = require('koa');
const kcors = require('kcors');
const KoaBody = require('koa-body');

const app = new Koa();

const PORT = process.env.PORT || 9010;

const admin = require('./api/admin');
const open = require('./api/open');

app.use(KoaBody());
app.use(kcors());
app.use(admin.routes());
app.use(open.routes());
app.use(admin.allowedMethods());
app.use(open.allowedMethods());

app.use(async (ctx, next) => {
  ctx.body = 'oops.';
});

app.listen(PORT, () => {
  console.log(`http://localhost:${PORT}`);
});
